package com.service.impl;

import com.dao.CommentDao;
import com.dao.impl.CommentDaoImpl;
import com.service.CommentService;

import java.util.List;
import java.util.Map;

public class CommentServiceImpl implements CommentService {
    CommentDao commentDao=new CommentDaoImpl();
    @Override
    public List<Map<String,Object>> queryAllComment(int foodId,int pageIndex,int pageSize) {
        List<Map<String,Object>> comments=commentDao.queryCommentsByFoodId(foodId,pageIndex,pageSize);
        if (comments!=null){
            return comments;
        }
        return null;
    }

    @Override
    public int addCommentByUserID(int userId, String comment, int foodId) {
        int addCommentByUserID=commentDao.addCommentByUserID(userId,comment,foodId);
        if (addCommentByUserID!=0){
            return addCommentByUserID;
        }
        return 0;
    }

    @Override
    public int getPageCount(int pageSize,int foodId) {
        int pageCount=0;
        int count = commentDao.getCount(foodId);
        pageCount = (count-1)/pageSize+1;
        return pageCount;
    }

    @Override
    public int deleteCommentById(int commentId) {
        int count =commentDao.deleteComment(commentId);
        return count;
    }

    @Override
    public int modifyComment(int commentId, String comment) {
        int count =commentDao.modifyComment(commentId,comment);
        return count;
    }


}
